#include "stdafx.h"
#include "PointSet.h"

#include <exception>

double PointSet::Euclidean2(unsigned int N, double* p1, double* p2)
{
	double sum = 0;
	for (unsigned int i = 0; i < N; ++i)
	{
		double di = p1[i] - p2[i];
		sum += di*di;
	}
	return sum;
}

PointSet::PointSet(unsigned int dimension, double* coord_max, double* coord_min)
{
	this->dimension = dimension;
	this->coord_max = new double[dimension];
	this->coord_min = new double[dimension];
	for (unsigned int i = 0; i < dimension; ++i)
	{
		this->coord_max[i] = coord_max[i];
		this->coord_min[i] = coord_min[i];
	}

	validation_initialization();
}


PointSet::~PointSet()
{
	delete[] coord_max;
	coord_max = NULL;
	delete[] coord_min;
	coord_min = NULL;
}


void PointSet::validation_initialization()
{
	if (dimension <= 0)
		throw new std::exception("EXCEPTION: dimension must be positive");
	for (unsigned int i = 0; i < dimension; ++i)
		if (coord_max[i] - coord_min[i] <= 0)
			throw std::exception("EXCEPTION: coordinate range in each dimension must be positive");
}


void PointSet::nearest_neighbor(double* key, double range, std::vector<double*>*& coords, std::vector<void*>*& results)
{
	throw new std::exception("EXCEPTION: invoking not implemented function");
}

void PointSet::nearest_neighbor(double* key, unsigned int k, std::vector<double*>*& coords, std::vector<void*>*& results)
{
	throw new std::exception("EXCEPTION: invoking not implemented function");
}

void PointSet::add_point(double* key, void* object)
{
	throw new std::exception("EXCEPTION: invoking not implemented function");
}

void PointSet::del_point(double* key, void* object)
{
	throw new std::exception("EXCEPTION: invoking not implemented function");
}

unsigned int PointSet::size()
{
	throw new std::exception("EXCEPTION: invoking not implemented function");
}

bool PointSet::inSpace(double* x)
{
	for (unsigned int i = 0; i < dimension; ++i)
		if (x[i]<coord_min[i] || x[i] > coord_max[i])
			return false;
	return true;
}